﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data;
using System.Data.SqlClient;
using System.IO;

using OgilvyOne.BLL;

public partial class GetExcelData : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string startdate = Request.Params["start"];
            string enddate = Request.Params["end"];
            switch (Request.Params["flg"])
            {
                case "1": GetExcel(""); break;
            }
        }
    }

    public void GetExcel(string filename)
    {
        string startdate = Request.Params["start"];
        string enddate = Request.Params["end"];
        DataTable dt = new UserBLL().GetExcel(startdate, enddate);
        StringWriter sw = new StringWriter();
        sw.WriteLine("姓氏,名称,用户邮箱,手机号,朋友名字1,朋友邮箱1,朋友名字2,朋友邮箱2,朋友名字3,朋友邮箱,语言,创建时间");
        foreach (DataRow dr in dt.Rows)
        {
            sw.WriteLine(dr["surName"] + "," + dr["presonalName"] + "," + dr["userEmail"] + "," + dr["mobile"] + "," + dr["friendName1"] + "," + dr["friendEmail1"] + "," + dr["friendName2"] + "," + dr["friendEmail2"] + "," + dr["friendName3"] + "," + dr["friendEmail3"] + "," + dr["language"] + "," + dr["creatTime"]);
        }
        sw.Close();
        Response.AddHeader("Content-Disposition", "attachment;  filename=" + filename + System.DateTime.Now.ToString("yyyyMMdd") + ".csv");
        Response.ContentType = "application/ms-excel";
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
        Response.Write(sw);
        Response.End();
    }
  }